package cn.lger.icollege.dao;

import cn.lger.icollege.entity.Student;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Code that Changed the World
 * Pro said
 * Created by Pro on 2018-04-14.
 */
@Repository
public interface StudentDao extends JpaRepository<Student, String> {

//    @Query("select s from Student s where s.username = ?1")
    Student findStudentByUsername(String username);


//    @Modifying
//    @Transactional
//    @Query("update Student s set s.name = :name, s.password = :password")
//    Student updateStudent(Student student);

    List<Student> findByClassroom_ClassId(Long classId);


    @Query("select s.news from Student s where s.username = :username")
    Integer findNewsNumByUsername(@Param("username") String username);

    List<Student> findAllByClassroomClassId(long classId, Sort sort);
}
